<?php

class musicsmodule {
	function name() { return "Music module"; }
	function description() { return ""; }
	function author() { return 'immanuel192'; }
	
	function hasSources() { return true; }
	function hasContent() { return true; }
	function hasViews() { return false; }
	
	function supportsWorkflow() { return false; }
	
	function show($view,$loc = null, $title = '') {
	}
    
    
	function searchName() {
	    $lang=exponent_lang_loadFile("modules/musicsmodule/class.php");
			return $lang['search_name'];
	}
	
	function spiderContent($item = null) {
		global $db;
		
		if (!defined('SYS_SEARCH')) require_once(BASE.'subsystems/search.php');
		$search = null;
		$search->category = 'Musics';
		$search->ref_module = 'musicsmodule';
		$search->ref_type = 'musics';
		
		if ($item) {
			$db->delete('search',"ref_module='musicsmodule' AND ref_type='musics' AND original_id=" . $item->id);
			$album=$db->selectObject('album','id = ' . $item->album_id);
            if ($album)
            {
			    $search->original_id = $item->id;
			    $search->title = ' ' . $item->name . ' ';
			    $search->keywords=$item->name;
			    $search->view_link = 'index.php?action=view&module=albummodule&id=' . $item->album_id;
			    $search->body= ' <font color="#808080">'. musicsmodule::make_small_part(exponent_search_removeHTML($item->info)) . ' </font>';
			    $search->location_data = $album->location_data;
			    $db->insertObject($search,'search');
            }
		} else {
			$db->delete('search',"ref_module='musicsmodule' AND ref_type='musics'");
			$temp = $db->selectObjects('musics');
			foreach ( $temp as $item) {
				// get albummodule
				$album=$db->selectObject('album','id = ' . $item->album_id);
                if ($album)
                {
				    $search->original_id = $item->id;
				    $search->title = ' ' . $item->name . ' ';
				    $search->keywords=$item->name;
				    $search->view_link = 'index.php?action=view&module=albummodule&id=' . $item->album_id;
				    $search->body= ' <font color="#808080">'. musicsmodule::make_small_part(exponent_search_removeHTML($item->info)) . ' </font>';
				    $search->location_data = $album->location_data;
				//eDebug($search);
				    $db->insertObject($search,'search');
                }
			}
		}
		
		return true;
	}
	
	function make_small_part($input)
	{
		$temp=strip_tags($input);
				// get first 100 chars
				$myreturn=substr($temp,0,300);
				$myindex=300;
				$mytest=substr($temp,$myindex,1);
				while (($mytest != ".") && ($myindex<strlen($temp)))
				{
					$myreturn=$myreturn . $mytest;
					$myindex++;
					$mytest=substr($temp,$myindex,1);
				}
				$myreturn.=".";
		if ($myreturn==".") $myreturn="";
		return $myreturn;
	}
	
	function make_info($music, $composer_name = "", $album_name = "")
	{
				$lang=exponent_lang_loadFile("modules/musicsmodule/info.php");
        $st_listen=$lang['listen'];
				$st_author=$lang['author'];
				$st_singer=$lang['singer'];
				$st_download=$lang['download'];
				$st_times=$lang['times'];
				$myreturn=musicsmodule::make_small_part($music->info);
				$music->info=$myreturn;
				
				$music->info=str_replace('"',"'",$music->info);
				$music->info=str_replace("\r\n","<br>",$music->info);
				$info="";
				if ($composer_name!='')
					$info="<b>{$st_author}</b>:&nbsp; {$composer_name}<br>";
				if ($music->singer!='')
					$info.="<b>{$st_singer}</b>: {$music->singer}<br>";
				if ($album_name !='')
				 	$info.="<b>Album</b>: {$album_name}<br>";
				$info.="<b>{$st_listen} </b>: {$music->listen_count}{$st_times}";
				if (isset($music->downloadable) && $music->downloadable==1)
					$info.=",&nbsp;<b>{$st_download}</b>: {$music->download_count}{$st_times}";
				$music->info=$info."<br>".$music->info;
				
		return $music;
	}
}

?>
